package com.nlx.notes.module.service.impl.gold;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nlx.notes.module.bean.dto.gold.GoldSalePageQueryDTO;
import com.nlx.notes.module.bean.vo.flow.GoldSaleSumOverviewVO;
import com.nlx.notes.module.core.consts.GlobalConst;
import com.nlx.notes.module.entity.GoldSaleOverviewEntity;
import com.nlx.notes.module.entity.GoldSaleRecordEntity;
import com.nlx.notes.module.mapper.GoldSaleOverviewMapper;
import com.nlx.notes.module.mapper.GoldSaleRecordMapper;
import com.nlx.notes.module.service.gold.GoldSaleRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class GoldSaleRecordServiceImpl extends ServiceImpl<GoldSaleRecordMapper, GoldSaleRecordEntity> implements GoldSaleRecordService {
    @Override
    public long countByCondition(GoldSalePageQueryDTO goldSalePageQueryDTO) {
        return this.getBaseMapper().selectCount(Wrappers.lambdaQuery(GoldSaleRecordEntity.class)
                .eq(GoldSaleRecordEntity::getUserId,goldSalePageQueryDTO.getUserId())
                .eq(GoldSaleRecordEntity::getDelFlag, GlobalConst.DEL_FLAG_NORMAL));
    }

    @Override
    public IPage<GoldSaleRecordEntity> pageByCondition(GoldSalePageQueryDTO goldSalePageQueryDTO) {
        IPage<GoldSaleRecordEntity> iPage = new Page<>(goldSalePageQueryDTO.getPage(),goldSalePageQueryDTO.getPageSize());
        return this.getBaseMapper().selectPage(iPage,Wrappers.lambdaQuery(GoldSaleRecordEntity.class)
                .eq(GoldSaleRecordEntity::getUserId, goldSalePageQueryDTO.getUserId())
                .eq(GoldSaleRecordEntity::getDelFlag, GlobalConst.DEL_FLAG_NORMAL)
                .orderByDesc(GoldSaleRecordEntity::getId));

    }

    @Override
    public GoldSaleSumOverviewVO sumByUserId(Long userId) {
        return this.getBaseMapper().sumByUserId(userId);
    }
}
